package javaee14.Controller;

import javaee14.Business.SaleService;
import javaee14.Model.Drink;
import javaee14.Model.In;
import javaee14.Model.Out;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class DrinkController {

    SaleService service;
@Autowired
    public void setService(SaleService service) {
        this.service = service;
    }

    @RequestMapping(value = "/index.html")
    public String index(){ return "index"; }
    @RequestMapping(value = "/index1.html")
    public String index1(){ return "index1"; }
    @RequestMapping(value = "/logincheck.html")
    public String logincheck(){ return "logincheck"; }

    @RequestMapping(value = "/shangpinindex.html")
    public String shangpininindex(HttpServletRequest request){
        request.getSession().setAttribute("drinks",service.Drinkqueryall());
    return  "shangpinindex";
    }
    @RequestMapping(value = "/failure.html")
    public String failure(){
        return  "failure";
    }

    @RequestMapping(value = "/InAdd.html")
    public String InAdd(){
        return  "InAdd";
    }

    @RequestMapping(value = "/InFind.html")
    public String InFind(){

    return  "InFind";
    }

    @RequestMapping(value = "/Inindex.html")
    public String Inindex(HttpServletRequest request){

        request.getSession().setAttribute("indrinks",service.Inqueryall());

        return  "Inindex";
    }

    @RequestMapping(value = "/InList.html")
    public String InList(){
        return  "InList";
    }

    @RequestMapping(value = "/OutAdd.html")
    public String OutAdd(){ return  "OutAdd";}

    @RequestMapping(value = "/OutFind.html")
    public String OutFind(){
        return  "OutFind";
    }

    @RequestMapping(value = "/Outindex.html")
    public String Outindex(HttpServletRequest request){
        request.getSession().setAttribute("outdrinks",service.Outqueryall());
    return  "Outindex";
    }

    @RequestMapping(value = "/OutList.html")
    public String OutList(){
        return  "OutList";
    }

    @RequestMapping(value = "/shangpinAdd.html")
    public String shangpinAdd(){ return  "shangpinAdd"; }

    @RequestMapping(value = "/shangpinDel.html")
    public String shangpinDel(){
        return  "shangpinDel";
    }

    @RequestMapping(value = "/shangpinFind.html")
    public String shangpinFind(){
        return  "shangpinFind";
    }

    @RequestMapping(value = "/shangpinUpdate.html")
    public String shangpinUpdate(){
        return  "shangpinUpdate";
    }

    @RequestMapping(value = "inadd.html")
    public String inadd(HttpServletRequest request, In in){
        service.Ininsrt(in);
        request.getSession().setAttribute("indrinks",service.Inqueryall());
        return  "Inindex";
    }
    @RequestMapping(value = "infind.html")
    public String infind(HttpServletRequest request,In in){
    In in1=service.Inquery(in);
    request.getSession().setAttribute("in1s",in1);
    return "InFind";
    }
    @RequestMapping(value = "inlist.html")
    public String inlist(HttpServletRequest request,In in){
    service.Indelete(in);
    return "InList";
    }
    @RequestMapping(value = "outadd.html")
    public String outadd(HttpServletRequest request, Out out){
        service.Outinsrt(out);
        request.getSession().setAttribute("outdrinks",service.Outqueryall());
        return "Outindex";
    }
    @RequestMapping(value = "outfind.html")
    public String infind(HttpServletRequest request,Out out){
        Out out1=service.Outquery(out);
        request.getSession().setAttribute("out1s",out1);
        return "OutFind";
    }
    @RequestMapping(value = "outlist.html")
    public String outlist(HttpServletRequest request,Out out){
        service.Outdelete(out);
        return "OutList";
    }
    @RequestMapping(value = "shangpinadd.html")
    public String shangpinadd(HttpServletRequest request, Drink drink){
       if(service.Drinkquery1(drink)==null)
       { service.Drinkinsrt(drink);
       request.getSession().setAttribute("drinks",service.Drinkqueryall());}
        return "shangpinindex";
    }
    @RequestMapping(value = "shangpindel.html")
    public String shangpindel(Drink drink){
        service.Drinkdelete(drink);
        return "shangpinDel";
    }
    @RequestMapping(value = "shangpinfind.html")
    public String shangpinfind(HttpServletRequest request, Drink drink){
        Drink drink1 =service.Drinkquery(drink);
        request.getSession().setAttribute("drinks1",drink1);
        return "shangpinFind";
    }

    @RequestMapping(value = "xiugai")
    public String xiugai(HttpServletRequest request,Drink drink){
    service.Drinkmodify(drink);
    return "shangpinindex";
    }

}
